package com.glaway.car.controller;

import com.glaway.car.Service.RecordService;
import com.glaway.car.dto.RecordDTO;
import com.glaway.car.dto.UserDTO;
import com.glaway.car.entity.Record;
import com.glaway.car.result.PageResult;
import com.glaway.car.result.Result;
import com.glaway.car.vo.ReportVO;
import com.glaway.car.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.LocalDate;

@RestController
public class RecordController {

    @Autowired
    RecordService recordService;
    private static final Logger log = LoggerFactory.getLogger(RecordController.class);

    /**
     * 记录分页查询
     * @param recordDTO recordDTO
     * @return Result
     */
    @GetMapping("/record")
    public Result queryRecord(RecordDTO recordDTO) {
        log.info("记录分页查询，recordQueryParam={}", recordDTO);
        PageResult<Record> pageResult = recordService.queryRecord(recordDTO);
        return Result.success(pageResult);
    }

    /**
     * 按用户统计分页查询
     * @param userDTO userDTO
     * @return Result
     */
    @GetMapping("/user")
    public Result queryUser(UserDTO userDTO) {
        log.info("用户分页查询，userQueryParam={}", userDTO);
        PageResult<UserVO> pageResult = recordService.queryUser(userDTO);
        log.info("用户分页查询结果：userPageResult={}", pageResult);
        return Result.success(pageResult);
    }

    /**
     * 按日统计查询
     * @param localDate localDate
     * @return Result
     */
    @GetMapping("/report")
    public Result queryReport(@RequestParam("date")@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate localDate) {
        log.info("统计查询，reportQueryParam={}", localDate);
        ReportVO reportVO = recordService.queryDayReport(localDate);
        return Result.success(reportVO);
    }

}
